package com.lee.dhsg.dao;
/**
 * @author Jun
 */

import java.util.List;
import java.util.Map;

import com.lee.dhsg.dao.provider.StudentSqlProvider;
import com.lee.dhsg.domain.Student;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component

@Mapper
public interface StudentDao {
    /**
     * 查询所有学生
     *
     * @return List<Student>
     */
    @Select("select * from student")
    List<Student> findAll();

    /**
     * 根据登录名和密码查询学生
     *
     * @param username
     * @param password
     * @return Student
     */
    @Select("select * from student where username = #{loginname} and password = #{password}")
    Student selectByLoginnameAndPassword(
            @Param("loginname") String username,
            @Param("password") String password);

    /**
     * 根据id查询学生
     *
     * @param sid
     * @return Student
     */
    @Select("select * from student where sid = #{sid}")
    @Results({
            @Result(id=true,column = "sid",property = "sid"),
            @Result(column = "realname",property ="realname" ),
            @Result(column = "IDCardNum" ,property ="iDCardNum" ),
            @Result(column = "IDCardImg01",property ="iDCardImg01" ),
            @Result(column = "IDCardImg02" ,property ="iDCardImg02" ),
            @Result(column = "IDCardVideo",property ="iDCardVideo" ),
            @Result(column = "username",property ="username" ),
            @Result(column = "password",property ="password" ),
            @Result(column = "sex",property ="sex" ),
            @Result(column = "icon" ,property ="icon" ),
            @Result(column = "signatrue",property ="signatrue" ),
            @Result(column = "description",property ="description" ),
            @Result(column = "tel",property ="tel" ),
            @Result(column = "email",property ="email" ),
            @Result(column = "lastlogin",property ="lastlogin" ),
            @Result(column = "realnameStatus",property ="realnameStatus" ),
            @Result(column = "checkStatus",property ="checkStatus" ),
            @Result(column = "sid",property = "orderList",
                    many = @Many(
                            select = "com.dhsg.dao.OrderDao.selectByOid",
                            fetchType = FetchType.LAZY
                    )),
            @Result(column = "sid",property = "courseList",
                    one=@One(
                            select = "com.dhsg.dao.CourseDao.seletCourseByTid",
                            fetchType = FetchType.LAZY
                    ))
    })
    Student selectById(Integer sid);

    /**
     * 学生注册所需
     *
     * @param username
     * @param password
     * @return Student
     */
    @Insert("insert into student(username,password) values(#{username},#{password})")
    int Signup(
            @Param("username") String username,
            @Param("password") String password);

    /**
     * 根据sid删除学生
     * @param sid
     */
    @Delete("delete from student where sid=#{sid}")
    void deleteBySid(Integer sid);

    /**
     * 动态查询学生
     *
     * @param params
     * @return List<Student>
     */
    @SelectProvider(type = StudentSqlProvider.class, method = "selectWhitParam")
    List<Student> selectByPage(Map<String, Object> params);

    /**
     * 动态插入学生
     *
     * @param student
     */
    @SelectProvider(type = StudentSqlProvider.class, method = "insertStudent")
    void save(Student student);


    /**
     * 动态更新学生
     * @param student
     */
		@SelectProvider(type=StudentSqlProvider.class,method="updateStudent")
		void update(Student student);







}
